package com.ktjy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.mapper.DevUserMapper;
import com.ktjy.pojo.DevUser;
import com.ktjy.service.DevUserService;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/devUser")
public class DevUserController {
    @Resource
    DevUserService devUserService;

    /**
     * 跳转登录页面
     * @return
     */
    @RequestMapping("/login")
    public String login(){
        return "devlogin";
    }

    //用户登录
    @RequestMapping("/devlogin")
    public String devlogin(@RequestParam String devCode,
                           @RequestParam String devPassword, HttpSession session
            , HttpServletRequest request) {
        DevUser devUser= devUserService.devlogin(devCode,devPassword);
        if(devUser !=null){
            session.setAttribute("devUserSession",devUser);
            return "redirect:/devUser/main";
        }else {
            request.setAttribute("error","账号或密码不正确");
            return "devlogin";
        }
    }
    //跳转到主页面
    @RequestMapping("/main")
    public String main(){
        return "/developer/main";
    }
}
